import '../../public.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({super.key});

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  @override
  void initState() {
    super.initState();
    // 延迟2秒后跳转到主页面
    Future.delayed(const Duration(seconds: 2), () {
      // 检查是否有登录信息
      final token = StorageManager.ls.getItem('token');
      if (token != null) {
        // 已登录，跳转到主页
        RouterHelper.navigator.pushNamedAndRemoveUntil(
          Routers.main,
          (route) => false,
        );
      } else {
        // 未登录，跳转到登录页
        RouterHelper.navigator.pushNamedAndRemoveUntil(
          Routers.login,
          (route) => false,
        );
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            // 应用Logo
            Image.asset(
              'assets/images/logo.png',
              width: 120,
              height: 120,
              fit: BoxFit.contain,
            ),
            const SizedBox(height: 30),
            // 应用名称
            const Text(
              'Naira Card',
              style: TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
                color: Colors.black,
              ),
            ),
            const SizedBox(height: 10),
            // 应用标语
            const Text(
              'Easier way to manage your cards',
              style: TextStyle(fontSize: 14, color: Colors.grey),
            ),
          ],
        ),
      ),
    );
  }
}
